package com.zb.controller;


import com.zb.common.R;
import com.zb.dto.DishDto;
import com.zb.entity.Dish;
import com.zb.entity.PageData;
import com.zb.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    DishService dishService;

    //新增菜品
    @PostMapping
    public R<Boolean> addDishWithFlavor(@RequestBody DishDto dishDto) {
        dishService.addDishWithFlavor(dishDto);
        return R.success(true,"新增菜品成功");
    }

    //分页查询菜品
    @GetMapping
    public R<PageData> selectDish(int page, int pageSize, String name) {

        PageData pageData = dishService.pageSelect(page, pageSize, name);
        return R.success(pageData, "查询员工成功");
    }

    /**
     * 根据id查询菜品信息与对应的口味信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<DishDto> getDishInfoById(@PathVariable Long id) {
        DishDto dishDto = dishService.getDishInfoById(id);
        return R.success(dishDto, "查询成功");
    }

    //更新菜品信息
    @PutMapping
    public R<Object> updateDishInfo(@RequestBody DishDto dishDto) {
        dishService.updateDishInfo(dishDto);
        return R.success(null, "更新成功");
    }


    //不分页查询菜品信息
    @GetMapping("/all")
    public R<List<Dish>> getAllDish(@RequestParam Dish dish) {
        List<Dish> dishList = dishService.getAllDish(dish);
        return R.success(dishList, "查询成功");
    }
}
